<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>GT pro钱包</title>
		<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
		<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
		<link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
		<link rel="stylesheet" href="bower_components/Ionicons/css/ionicons.min.css">
		<link rel="stylesheet" href="bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css">
		<link rel="stylesheet" href="dist/css/AdminLTE.min.css">
		<link rel="stylesheet" href="dist/css/skins/skin-blue.min.css">
		<link rel="stylesheet" href="css/style.css">
		<link rel="stylesheet" href="css/card.css">
		<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">

		<link rel="stylesheet" href="bower_components/bootstrap-daterangepicker/daterangepicker.css">
		<link rel="stylesheet" href="bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">
	</head>

	<body class="hold-transition skin-blue sidebar-mini">
		<div class="wrapper">
			<div class="content-wrapper">
				<section class="content-header">
					<ol class="breadcrumb">
						<li>
							<a href="#"><i class="fa fa-dashboard"></i>质押引力池管理</a>
						</li>
						<li class="active">兑换记录</li>
					</ol>
				</section>
				<section class="content">
					<div class="box">
						<div class="box-header with-border">
							兑换记录
						</div>
						<div class="box-body">
							<div class="buyu_search_group">
								<div class="row" style="margin-bottom:10px;">
									<div class="col-xs-12 col-sm-6 col-lg-3">
										<div class="input-group margin">
											<div class="input-group-btn">
												<!-- 用户id，开始时间，结束时间 -->
												<button type="button" class="btn btn-default" aria-expanded="false">用户id</button>
											</div>
											<input type="text" class="form-control" id="user_id">
										</div>
									</div>
									<div class="col-xs-12 col-sm-6 col-lg-3">
										<div class="input-group margin">
											<div class="input-group-btn">
												<button type="button" class="btn btn-default" aria-expanded="false">时间</button>
											</div>
											<!-- /btn-group -->
											<input type="text" class="form-control" id="select_time" autocomplete="off">
											<div class="input-group-addon clearBtns" onclick="clearRangeTime(this)">x</div>
										</div>
									</div>
									<div class="col-xs-12 col-sm-6 col-lg-3">
										<button type="button" class="btn bg-primary margin" onclick="search()"><i class="fa fa-search" ></i>&nbsp;搜索</button>
										<button type="button" class="btn bg-primary margin" onclick="reset()"><i class="fa fa-trash" ></i>&nbsp;重置</button>
									</div>
								</div>
							</div>
						</div>
						<div class="row">
							<div class="col-xs-12">
								<!-- /.box-header -->
								<div class="box-body">
									<table id="example" class="display nowrap table table-bordered table-striped" style="width:100%;">
										<thead>
											<tr>
												<!-- //id，，用户id，兑换支出(如：100 USDT)，兑换获得(如：100 GT)，时间 -->
												<th>ID</th>
												<th>用户ID</th>
												<th>兑换支出</th>
												<th>兑换获得</th>
												<th>时间</th>
											</tr>
										</thead>
										<tbody></tbody>
									</table>
									<div class="dealSum clearfix" >
										<div style="float:left">
											USDT数量：<span id="usdt_number_sum">--</span>
										</div>
										<div style="float:left;margin-left:20px;">
											兑换所得GT数量：<span id="ex_coin_number_sum">--</span>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</section>
			</div>
		</div>
		
		<div id='NewsToolBox'></div>
		<script src="bower_components/jquery/dist/jquery.min.js"></script>
		<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
		<script src="bower_components/datatables.net/js/jquery.dataTables.min.js"></script>
		<script src="bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>

		<script src="bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
		<script src="bower_components/moment/min/moment.min.js"></script>
		<script src="bower_components/bootstrap-daterangepicker/daterangepicker.js"></script>
		<script src="dist/js/adminlte.min.js"></script>
		<script src="js/argument.js"></script>
		<script src="js/fun.js"></script>
		<script src="js/nav.js"></script>
		<script src="js/pop.js"></script>
		<script type="text/javascript">
			$('#select_time').daterangepicker({
				timePicker: true,
				timePicker24Hour: true,
				autoUpdateInput: false,
				locale: {
					format: "YYYY-MM-DD HH:mm"
				}
			})
			var table = $('#example').DataTable({
				'ordering': false,
				'lengthChange': false,
				'searching': false,
				'info': true,
				"processing": true,
				"serverSide": true,
				'scrollX':true,
				"ajax": {
					"type": 'post',
					"url": url + "Back_ExchangeLog",
					"contentType": "application/x-www-form-urlencoded",
					"headers": {
						"auth-token": localStorage.getItem("wallet_token")
					},
					"data": function(d) {
						var dataType = {
							need_pledge: {
								type: 'string',
								value: $("#need_pledge").val()
							},
							coin_id: {
								type: 'string',
								value: $("#coin_id").val()
							},
							start_time: {
								type: 'time',
								value: $("#select_time").val().substring(0, 16)
							},
							end_time: {
								type: 'time',
								value: $("#select_time").val().substring(19, 35)
							}
						}
						var Json = renderData(dataType);
						Json.page_num = d.start / 10 + 1;
						var data = {};
						data.data = JSON.stringify(Json);
						return data;
					},
					"dataFilter": function(data) {
						var datajson = eval('(' + data + ')');
						if(datajson.status == 1000||datajson.status == 102) {
							ToLogin(datajson)
							return false;
						} else if(datajson.status != 1) {
							alert(datajson.error);
							return false;
						}
						
						 $("#ex_coin_number_sum").text(datajson.data.ex_coin_number_sum)
						 $("#usdt_number_sum").text(datajson.data.usdt_number_sum)
						var json = {};
						if(datajson.data == null) {
							json.recordsTotal = 0;
							json.recordsFiltered = 0;
							json.data = [];
							return JSON.stringify(json);
						} else {
							json.recordsTotal = datajson.data.total;
							json.recordsFiltered = datajson.data.total;
							json.data = datajson.data.data_list;
							return JSON.stringify(json);
						}
					}
				},
				
				"columns": [{
						data: 'id'
					},
					{
						data: 'user_id'
					},
					{
						data: null,
						render: function(data) {
							return '<i class="fa fa-fw fa-database"></i>&nbsp;' + data.usdt_number + "&nbsp;USDT"
						}
					},
					{
						data: null,
						render: function(data) {
							return '<i class="fa fa-fw fa-database"></i>&nbsp;' + data.ex_coin_number + "&nbsp;" + data.ex_coin_name
						}
					},
					{
						data: 'add_time'
					},
				]
			})
		</script>

		<script type="text/javascript">
			// 复制全文

			$("#example").on("click", ".copy", function() {

				var text = $(this).siblings(".address_content").text();
				console.log(text)
				var flag = copyText(text);
				move('success', '复制成功')
			})

			function copyText(text) {
				var textarea = document.createElement("textarea"); //创建input对象
				var currentFocus = document.activeElement; //当前获得焦点的元素
				var toolBoxwrap = document.getElementById('NewsToolBox'); //将文本框插入到NewsToolBox这个之后
				console.log(toolBoxwrap)
				toolBoxwrap.appendChild(textarea); //添加元素
				textarea.value = text;
				textarea.focus();
				if(textarea.setSelectionRange) {
					textarea.setSelectionRange(0, textarea.value.length); //获取光标起始位置到结束位置
				} else {
					textarea.select();
				}
				try {
					var flag = document.execCommand("copy"); //执行复制
				} catch(eo) {
					var flag = false;
				}
				toolBoxwrap.removeChild(textarea); //删除元素
				currentFocus.focus();
				return flag;
			}
		</script>

		<script type="text/javascript">
			function addproject() {
				$("#addprojectModal").modal('show');
				$("#addprojectModal input[type=text]").val("");
			}

			function addSave() {
				$.ajax({
					type: 'post',
					url: url + "Back_ProjectAdd",
					contentType: "application/x-www-form-urlencoded",
					headers: {
						"auth-token": localStorage.getItem("wallet_token")
					},
					data: {
						data: JSON.stringify({
							account: $("#addprojectModal [name=account]").val(),
							password: $("#addprojectModal [name=password]").val(),
							phone: $("#addprojectModal [name=phone]").val(),
							coin_id: $("#addprojectModal [name=coin_id]").val(),
							address: $("#addprojectModal [name=address]").val(),
							usd_address: $("#addprojectModal [name=usd_address]").val(),
						})
					},
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							ToLogin(res)
							return false;
						} else if(res.status != 1) {
							alert(res.error);
							return false;
						}
						move('success', res.error)
						$("#addprojectModal").modal("hide");
						table.draw(false);
					}
				})
			}
			//

			$("#example").on("click", ".Status", function() {
				var status = 1,
					_this = $(this),
					id = _this.attr('statusid');
				if($(this).hasClass("active")) {
					status = 0;
				}

				$("#passwordModal [name=id]").val(id);
				$("#passwordModal [name=status]").val(status);
				$("#passwordModal").modal("show");
			})

			function changeSave() {
				$.ajax({
					type: 'post',
					url: url + 'Back_ProjectUpdate',
					contentType: "application/x-www-form-urlencoded",
					headers: {
						"auth-token": localStorage.getItem("wallet_token")
					},
					data: {
						data: JSON.stringify({
							id: $("#passwordModal [name=id]").val(),
							need_pledge: Number($("#passwordModal [name=status]").val()),
							op_password: $("#passwordModal [name=op_password]").val(),
							status: 1
						})
					},
					dataType: 'json',
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							ToLogin(res)
							return false;
						} else if(res.status != 1) {
							alert(res.msg);
							return false;
						}

						var _this = $(".Status[statusId=" + $("#passwordModal [name=id]").val() + "]");
						$("#passwordModal").modal('hide');
						if($("#passwordModal [name=status]").val() == 0) {
							_this.removeClass("active");
							_this.find(".fr_swich_txt").text("不需要");
						} else {
							_this.addClass("active");
							_this.find(".fr_swich_txt").text("需要");
						}

					}
				})
			}
			//				
			//			})

			function editProject(_this) {
				var data = JSON.parse($(_this).siblings("input").val());
//				if(data.need_pledge == 0) {
//					$("#editprojectModal [name=pledge_num]").prop("disabled", true);
//				} else {
//					$("#editprojectModal [name=pledge_num]").prop("disabled", false);
//				}
				$.each(data, function(index, item) {
					if(index == 'password') {
						return;
					}
					$("#editprojectModal [name=" + index + "]").val(item);
				})
				$("#editprojectModal [name = orig_address]").val(data.address)
				$("#editprojectModal [name = pledge_num]").val(0)
				$("#editprojectModal").modal("show");
			}

			function editSave() {
				if($("#editprojectModal [name=op_password]").val() == "") {
					alert("请填写操作密码");
					return false;
				}
				var data = {
					account: $("#editprojectModal [name=account]").val(),
					phone: $("#editprojectModal [name=phone]").val(),
					pledge_num: $("#editprojectModal [name=pledge_num]").val(),
					op_password: $("#editprojectModal [name=op_password]").val(),
					id: $("#editprojectModal [name=id]").val(),
				}
				if($("#editprojectModal [name=orig_address]").val() != $("#editprojectModal [name=address]").val()) {
					data.address = $("#editprojectModal [name=address]").val()
				}
				if($("#editprojectModal [name=password]").val() != "") {
					data.password = $("#editprojectModal [name=password]").val()
				}
				$("[name = op_password]").val("");
				$.ajax({
					type: 'post',
					url: url + 'Back_ProjectUpdate',
					contentType: "application/x-www-form-urlencoded",
					headers: {
						"auth-token": localStorage.getItem("wallet_token")
					},
					data: {
						data: JSON.stringify(data)
					},
					dataType: 'json',
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							ToLogin(res)
							return false;
						} else if(res.status != 1) {
							alert(res.msg);
							return false;
						}
						$("#editprojectModal").modal("hide");
						move("success", res.error);
						table.draw(false);
					}
				})
			}

			function Transfer(_this) {
				var data = JSON.parse($(_this).siblings("input").val());
				$("#transferModal").modal('show');
				$("#transferModal [name = op_password]").val("");
				$("#transferModal [name = coin_id]").attr("coin_id", data.coin_id)
			}

			function transferSave() {
				var data = {
					op_password: $("#transferModal [name=op_password]").val(),
					coin_num: $("#transferModal [name=coin_num]").val(),
					coin_id: $("#transferModal [name=coin_id]").attr("coin_id"),
				}
				$.ajax({
					type: 'post',
					url: url + 'Back_TransferCoinByPro',
					contentType: "application/x-www-form-urlencoded",
					headers: {
						"auth-token": localStorage.getItem("wallet_token")
					},
					data: {
						data: JSON.stringify(data)
					},
					dataType: 'json',
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							ToLogin(res)
							return false;
						} else if(res.status != 1) {
							alert(res.msg);
							return false;
						}
						$("#transferModal").modal("hide");
						move("success", res.error);
						table.draw(false);
					}
				})
			}
			
			function recharge(_this){
				console.log($(_this).siblings("input").val())
				var data = JSON.parse($(_this).siblings("input").val());
				$("#rechargeModal").modal('show');
				$("#rechargeModal [name = op_password]").val("");
				$("#rechargeModal [name = id]").val(data.id);
			}
			
			function rechargeSave(){
				if($("#rechargeModal [name=op_password]").val() == "") {
					alert("请填写操作密码");
					return false;
				}
				var data = {
					pledge_num: $("#rechargeModal [name=pledge_num]").val(),
					op_password: $("#rechargeModal [name=op_password]").val(),
					id: $("#rechargeModal [name=id]").val(),
				}
				$("[name = op_password]").val("");
				$.ajax({
					type: 'post',
					url: url + 'Back_ProjectUpdate',
					contentType: "application/x-www-form-urlencoded",
					headers: {
						"auth-token": localStorage.getItem("wallet_token")
					},
					data: {
						data: JSON.stringify(data)
					},
					dataType: 'json',
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							ToLogin(res)
							return false;
						} else if(res.status != 1) {
							alert(res.msg);
							return false;
						}
						$("#rechargeModal").modal("hide");
						move("success", res.error);
						table.draw(false);
					}
				})
			}
		</script>
	</body>

</html>